import {StarType} from "./Type.ts";

let starTypeData: Array<StarType> = []

let starTypeMap = new Map<number, StarType>()

let starTypeIdNameMap = new Map<number, string>()

export let loadStarTypeData = (): Array<StarType> => {
    if (starTypeData.length > 0) {
        return [...starTypeData]
    }
    for (let i of defaultData) {
        starTypeData.push(Object.assign(new StarType(), i))
    }
    return [...starTypeData]
}

export let loadStarTypeMap = (): Map<number, StarType> => {
    if (starTypeMap.size > 0) {
        return new Map(starTypeMap)
    }
    for (let starType of loadStarTypeData()) {
        starTypeMap.set(starType.id, starType)
    }
    return new Map(starTypeMap)
}

export let loadStarTypeIdNameMap = (): Map<number, string> => {
    if (starTypeIdNameMap.size > 0) {
        return new Map(starTypeIdNameMap)
    }
    for (let starType of loadStarTypeData()) {
        starTypeIdNameMap.set(starType.id, starType.name)
    }
    return new Map(starTypeIdNameMap)
}

let defaultData: Array<any> = [
    {
        "id": 1,
        "name": "M型",
        "percent": 6,
        "luminosityMin": 0.78,
        "luminosityMax": 0.89,
        "rare": 2.5,
        "planetMin": 1,
        "planetMax": 4,
        "hot": 0.45,
        "warm": 0.46,
        "cold": 1.59,
        "gas": 0.31
    }, {
        "id": 2,
        "name": "K型",
        "percent": 16,
        "luminosityMin": 0.89,
        "luminosityMax": 0.96,
        "rare": 1,
        "planetMin": 1,
        "planetMax": 5,
        "hot": 0.77,
        "warm": 0.55,
        "cold": 1.42,
        "gas": 0.31
    }, {
        "id": 3,
        "name": "G型",
        "percent": 19,
        "luminosityMin": 0.96,
        "luminosityMax": 1.04,
        "rare": 0.7,
        "planetMin": 3,
        "planetMax": 5,
        "hot": 1.34,
        "warm": 0.62,
        "cold": 1.31,
        "gas": 0.42
    }, {
        "id": 4,
        "name": "F型",
        "percent": 8,
        "luminosityMin": 1.04,
        "luminosityMax": 1.13,
        "rare": 0.6,
        "planetMin": 3,
        "planetMax": 5,
        "hot": 1.63,
        "warm": 0.55,
        "cold": 1.18,
        "gas": 0.47
    }, {
        "id": 5,
        "name": "A型",
        "percent": 5,
        "luminosityMin": 1.13,
        "luminosityMax": 1.39,
        "rare": 1,
        "planetMin": 3,
        "planetMax": 5,
        "hot": 2.16,
        "warm": 0.29,
        "cold": 0.93,
        "gas": 0.57
    }, {
        "id": 6,
        "name": "B型",
        "percent": 31,
        "luminosityMin": 1.39,
        "luminosityMax": 2.02,
        "rare": 0.4,
        "planetMin": 4,
        "planetMax": 6,
        "hot": 2.78,
        "warm": 0.11,
        "cold": 1.31,
        "gas": 0.76
    }, {
        "id": 7,
        "name": "O型",
        "percent": 3,
        "luminosityMin": 2.02,
        "luminosityMax": 2.51,
        "rare": 1.6,
        "planetMin": 5,
        "planetMax": 6,
        "hot": 3.37,
        "warm": 0.11,
        "cold": 1.21,
        "gas": 0.83
    }, {
        "id": 8,
        "name": "蓝巨星",
        "percent": 1,
        "luminosityMin": 1.66,
        "luminosityMax": 2.76,
        "rare": 2.5,
        "planetMin": 1,
        "planetMax": 3,
        "hot": 1.34,
        "warm": 0,
        "cold": 0.01,
        "gas": 0.55
    }, {
        "id": 9,
        "name": "红巨星",
        "percent": 2,
        "luminosityMin": 0.83,
        "luminosityMax": 1.12,
        "rare": 2.5,
        "planetMin": 1,
        "planetMax": 3,
        "hot": 1.35,
        "warm": 0.1,
        "cold": 0.01,
        "gas": 0.55
    }, {
        "id": 10,
        "name": "黄巨星",
        "percent": 2,
        "luminosityMin": 0.83,
        "luminosityMax": 1.12,
        "rare": 2.5,
        "planetMin": 1,
        "planetMax": 3,
        "hot": 1.35,
        "warm": 0.1,
        "cold": 0.01,
        "gas": 0.55
    }, {
        "id": 11,
        "name": "白巨星",
        "percent": 2,
        "luminosityMin": 0.83,
        "luminosityMax": 1.12,
        "rare": 2.5,
        "planetMin": 1,
        "planetMax": 3,
        "hot": 1.35,
        "warm": 0.1,
        "cold": 0.01,
        "gas": 0.55
    }, {
        "id": 12,
        "name": "白矮星",
        "percent": 3,
        "luminosityMin": 0.28,
        "luminosityMax": 0.47,
        "rare": 3.5,
        "planetMin": 1,
        "planetMax": 2,
        "hot": 0,
        "warm": 0,
        "cold": 1,
        "gas": 0.21
    }, {
        "id": 13,
        "name": "中子星",
        "percent": 1,
        "luminosityMin": 0.61,
        "luminosityMax": 0.78,
        "rare": 4.5,
        "planetMin": 1,
        "planetMax": 1,
        "hot": 0,
        "warm": 0,
        "cold": 1,
        "gas": 0
    }, {
        "id": 14,
        "name": "黑洞",
        "percent": 1,
        "luminosityMin": 0.16,
        "luminosityMax": 0.21,
        "rare": 5,
        "planetMin": 1,
        "planetMax": 1,
        "hot": 0,
        "warm": 0,
        "cold": 1,
        "gas": 0
    }
]